/**
 * Created by Coing on 2017/2/26.
 */
public class Solution {
    public boolean canConstruct(String ransomNote, String magazine) {

        int[] arr = new int[26];
        // 统计magazine在26个字符出现的个数
        for (int i = 0; i < magazine.length(); i++) {
            arr[magazine.charAt(i) - 'a']++;
        }

        int ransomlen = 0;
        // 计算 ransomNote 在上述结果后， 进行相减
        for (int i = 0; i < ransomNote.length(); i++) {
            ransomlen = --arr[ransomNote.charAt(i) - 'a'];
            if(ransomlen < 0){
                return false;
            }
        }
        // 能够到达最后 就 true
        return true;
    }

    public static void main(String[] args) {
            Solution solution = new Solution();
            System.out.println(solution.canConstruct("a", "b"));
            System.out.println(solution.canConstruct("aa", "ab"));
            System.out.println(solution.canConstruct("aa", "aab"));

    }


}
